package com.netease.nie.controllers;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.netease.nie.base.controllers.BaseController;
import com.netease.nie.base.exceptions.BusinessException;
import com.netease.nie.constants.BusinessConstants;
import com.netease.nie.dto.ExchangeGoodsInfoListDto;
import com.netease.nie.facade.PrivilegeGoodsListFacade;

/**
 * 我可领取特权
 * @author wwbn3695
 * @createDate June 25th,2016
 *
 */
@RestController
@RequestMapping("/api/my_privilege")
public class PrivilegeGoodsController extends BaseController {
	
	@Autowired
	private PrivilegeGoodsListFacade privilegeGoodsListFacade;
	
	@RequestMapping(value = "/goods_list", method = RequestMethod.GET, produces = "application/json")
	public String myPrivilegeGoodsList(HttpServletRequest request) throws Exception {
		Long userId = (Long) request.getAttribute("userId");
		if (userId == null)
			throw new BusinessException(BusinessConstants.USER_NOT_LOGIN.getCode(), "用户未登录");
		Integer page = Integer.valueOf(StringUtils.isBlank(request.getParameter("page")) ? "1" : request.getParameter("page"));
		
		List<ExchangeGoodsInfoListDto> exchangeGoodsInfoListDtos = privilegeGoodsListFacade.listGoodsInfoDtoByUserPrivilegeLevel(userId, page);
		return jsonSuccess(exchangeGoodsInfoListDtos);
	}

}
